<template>
  <el-dialog title="导入" :close-on-click-modal="false" :visible.sync="visible" customClass="customWidth">
    <el-upload class="upload-demo" ref="upload" name="filename" :before-upload="beforeUploadHandle" :action="this.$http.adornUrl(`/generator/studentmanage/import?token=${this.$cookie.get('token')}`)"
      :before-remove="beforeRemove" :on-success="successHandle" multiple :limit="1" :on-exceed="handleExceed">
      <el-button size="small" type="primary">选择文件</el-button>
    </el-upload>
    <div style="height: 500px; width:100%; ">
      <el-table :data="dataList" border height="500" v-loading="dataListLoading">
        <el-table-column prop="studentName" header-align="center" align="center" label="学员姓名">
        </el-table-column>
        <el-table-column prop="studentId" header-align="center" align="center" label="学员ID">
        </el-table-column>
        <el-table-column prop="studentStage" header-align="center" align="center" label="学员阶段">
        </el-table-column>
        <el-table-column prop="listeningIntentionality" :formatter="intentionFormatter" header-align="center" align="center" label="试听意向度">
        </el-table-column>
        <el-table-column prop="sourceChannel" :formatter="sourceChannelFormatter" header-align="center" align="center" label="来源渠道">
        </el-table-column>
        <el-table-column prop="followStatus" :formatter="followStatusFormatter" header-align="center" align="center" label="跟进状态	">
        </el-table-column>
        <el-table-column prop="followTime" header-align="center" align="center" label="上次跟进时间">
        </el-table-column>
        <el-table-column prop="createAt" header-align="center" align="center" label="入库时间">
        </el-table-column>
        <el-table-column prop="classroomStatus" :formatter="classroomStatusFormatter" header-align="center" align="center" label="课堂状态">
        </el-table-column>
        <el-table-column prop="attendanceStatus" :formatter="attendanceStatusFormatter"  header-align="center" align="center" label="考勤状态">
        </el-table-column>
        <el-table-column prop="isUnsubscribe" :formatter="isUnsubscribeFormatter" header-align="center" align="center" label="是否退订">
        </el-table-column>
        <el-table-column prop="auditionTime" header-align="center" align="center" label="试听时间">
        </el-table-column>
        <el-table-column prop="appointmentPerson" header-align="center" align="center" label="预约人">
        </el-table-column>
        <el-table-column prop="appointmentTime" header-align="center" align="center" label="预约时间">
        </el-table-column>
        <el-table-column prop="registrationIntention" :formatter="registrationIntentionFormatter" header-align="center" align="center" label="报名意向度">
        </el-table-column>
        <el-table-column prop="studentType" :formatter="studentTypeFormatter" header-align="center" align="center" label="学员类型">
        </el-table-column>
        <el-table-column prop="studentStatus" :formatter="studentStatusFormatter" header-align="center" align="center" label="学员状态">
        </el-table-column>
        <el-table-column prop="coachTeacher" header-align="center" align="center" label="辅导老师">
        </el-table-column>
        <el-table-column prop="renewalIntention" :formatter="renewalIntentionFormatter" header-align="center" align="center" label="续费意向度">
        </el-table-column>
        <el-table-column prop="introductionIntention" :formatter="introductionIntentionFormatter" header-align="center" align="center" label="转介绍意向度">
        </el-table-column>
        <el-table-column prop="curriculaTime" header-align="center" align="center" label="开课时间">
        </el-table-column>
      </el-table>
    </div>

  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataList: [],
        dataListLoading: false,
        importUrl: ''
      }
    },
    methods: {
      init () {
        this.visible = true
        this.$refs.upload.clearFiles()
        this.dataList = []
      },
      // 上传文件及批量导入学生信息功能
      beforeUploadHandle (file) {
        this.dataListLoading = true
      },
      handleExceed (files, fileList) {
        this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
      },
      beforeRemove (file, fileList) {
        return this.$confirm(`确定移除 ${file.name}?`)
      },
      successHandle (response, file, fileList) {
        this.dataListLoading = false
        if (response.code === 0) {
          this.dataList = response.list
          this.$message('上传成功！')
          console.log(response)
        } else {
          this.$message.error(response.msg)
        }
      },
      // 格式化试听意向度
      intentionFormatter (row, column) {
        let listeningIntentionality = row.listeningIntentionality
        if (listeningIntentionality === 0) {
          return '未标记'
        } else if (listeningIntentionality === 1) {
          return '无'
        } else if (listeningIntentionality === 2) {
          return '低'
        } else if (listeningIntentionality === 3) {
          return '中'
        } else if (listeningIntentionality === 4) {
          return '高'
        } else {
          return ''
        }
      },
      // 格式化报名意向度
      registrationIntentionFormatter (row, column) {
        let registrationIntention = row.registrationIntention
        if (registrationIntention === 0) {
          return '未标记'
        } else if (registrationIntention === 1) {
          return '无'
        } else if (registrationIntention === 2) {
          return '低'
        } else if (registrationIntention === 3) {
          return '中'
        } else if (registrationIntention === 4) {
          return '高'
        } else {
          return ''
        }
      },
      // 格式化续费意向度
      renewalIntentionFormatter (row, column) {
        let renewalIntention = row.renewalIntention
        if (renewalIntention === 0) {
          return '未标记'
        } else if (renewalIntention === 1) {
          return '无'
        } else if (renewalIntention === 2) {
          return '低'
        } else if (renewalIntention === 3) {
          return '中'
        } else if (renewalIntention === 4) {
          return '高'
        } else {
          return ''
        }
      },
      // 格式化转介绍意向度
      introductionIntentionFormatter (row, column) {
        let introductionIntention = row.introductionIntention
        if (introductionIntention === 0) {
          return '未标记'
        } else if (introductionIntention === 1) {
          return '无'
        } else if (introductionIntention === 2) {
          return '低'
        } else if (introductionIntention === 3) {
          return '中'
        } else if (introductionIntention === 4) {
          return '高'
        } else {
          return ''
        }
      },
      // 格式化来源渠道
      sourceChannelFormatter (row, column) {
        let sourceChannel = row.sourceChannel
        if (sourceChannel === 0) {
          return '无'
        } else if (sourceChannel === 1) {
          return '公告投放'
        } else if (sourceChannel === 2) {
          return '商场地推'
        } else {
          return ''
        }
      },
      // 格式化跟进状态
      followStatusFormatter (row, column) {
        let followStatus = row.followStatus
        if (followStatus === 0) {
          return '未跟进'
        } else if (followStatus === 1) {
          return '跟进中'
        } else {
          return ''
        }
      },
      // 格式化课堂状态
      classroomStatusFormatter (row, column) {
        let classroomStatus = row.classroomStatus
        if (classroomStatus === 0) {
          return '未开始'
        } else if (classroomStatus === 1) {
          return '正在进行'
        } else if (classroomStatus === 2) {
          return '已结束'
        } else if (classroomStatus === 3) {
          return '已取消'
        } else {
          return ''
        }
      },
      // 格式化考勤状态
      attendanceStatusFormatter (row, column) {
        let attendanceStatus = row.attendanceStatus
        if (attendanceStatus === 0) {
          return '缺席'
        } else if (attendanceStatus === 1) {
          return '出席'
        } else if (attendanceStatus === 2) {
          return '迟到'
        } else {
          return ''
        }
      },
      // 格式化是否退订
      isUnsubscribeFormatter (row, column) {
        let isUnsubscribe = row.isUnsubscribe
        if (isUnsubscribe === 0) {
          return '未退订'
        } else if (isUnsubscribe === 1) {
          return '已退订'
        } else {
          return ''
        }
      },
      // 格式化学员类型
      studentTypeFormatter (row, column) {
        let studentType = row.studentType
        if (studentType === 0) {
          return '体验'
        } else if (studentType === 1) {
          return 'VIP'
        } else if (studentType === 2) {
          return 'SVIP'
        } else {
          return ''
        }
      },
      // 格式化学员状态
      studentStatusFormatter (row, column) {
        let studentStatus = row.studentStatus
        if (studentStatus === 0) {
          return '未开课'
        } else if (studentStatus === 1) {
          return '在读'
        } else if (studentStatus === 2) {
          return '休学'
        } else if (studentStatus === 3) {
          return '毕业'
        } else if (studentStatus === 4) {
          return '退费'
        } else {
          return ''
        }
      }
    }
  }
</script>
<style>
  .customWidth {
    width: 80%;
  }
</style>
